

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/memory_blog/img/fluid.png">
  <link rel="icon" href="/memory_blog/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="🌭 分布式协作：探索服务注册与发现的最佳实践">
<meta property="og:type" content="article">
<meta property="og:title" content="从零开始构建分布式服务架构：用 &#96;Dubbo&#96; 和注册中心实现远程调用、服务注册与发现、配置管理">
<meta property="og:url" content="https://test.atomgit.net/memory_blog/2023/08/22/%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E6%9E%84%E5%BB%BA%E5%88%86%E5%B8%83%E5%BC%8F%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84%EF%BC%9A%E7%94%A8Dubbo%E5%92%8C%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83%E5%AE%9E%E7%8E%B0%E8%BF%9C%E7%A8%8B%E8%B0%83%E7%94%A8%E3%80%81%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0%E3%80%81%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="🌭 分布式协作：探索服务注册与发现的最佳实践">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://test.atomgit.net/memory_blog/img/artical/farm.jpg">
<meta property="article:published_time" content="2023-08-22T03:45:17.000Z">
<meta property="article:modified_time" content="2024-06-14T08:50:17.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="微服务">
<meta property="article:tag" content="SpringCloud">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://test.atomgit.net/memory_blog/img/artical/farm.jpg">
  
  
  
  <title>从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/memory_blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/memory_blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/memory_blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"test.atomgit.net","root":"/memory_blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/memory_blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/memory_blog/js/utils.js" ></script>
  <script  src="/memory_blog/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/memory_blog/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/memory_blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/memory_blog/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-08-22 11:45" pubdate>
          2023年8月22日 中午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          16k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          39 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="微服务"
        id="heading-79c287218d34050f6bd19986cd05b499" role="tab" data-toggle="collapse" href="#collapse-79c287218d34050f6bd19986cd05b499"
        aria-expanded="true"
      >
        微服务
        <span class="list-group-count">(2)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-79c287218d34050f6bd19986cd05b499"
           role="tabpanel" aria-labelledby="heading-79c287218d34050f6bd19986cd05b499">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem collapsed
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="API 网关"
        id="heading-f46400f593d3ebd877f55308b9b89dd0" role="tab" data-toggle="collapse" href="#collapse-f46400f593d3ebd877f55308b9b89dd0"
        aria-expanded="false"
      >
        API 网关
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse " id="collapse-f46400f593d3ebd877f55308b9b89dd0"
           role="tabpanel" aria-labelledby="heading-f46400f593d3ebd877f55308b9b89dd0">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem collapsed
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="Spring Cloud Gateway"
        id="heading-3c80ac4933323545e2945786f8a35ebc" role="tab" data-toggle="collapse" href="#collapse-3c80ac4933323545e2945786f8a35ebc"
        aria-expanded="false"
      >
        Spring Cloud Gateway
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse " id="collapse-3c80ac4933323545e2945786f8a35ebc"
           role="tabpanel" aria-labelledby="heading-3c80ac4933323545e2945786f8a35ebc">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/memory_blog/2023/08/17/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%20API%20%E7%BD%91%E5%85%B3%EF%BC%9A%E5%8E%9F%E7%90%86%E3%80%81%E5%8A%9F%E8%83%BD%E5%92%8C%E7%94%A8%E9%80%94/" title="深入理解 API 网关：原理、功能和用途"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">深入理解 API 网关：原理、功能和用途</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="SpringCloud"
        id="heading-cfb5f1b5888a24efc43a5f3a4b37d137" role="tab" data-toggle="collapse" href="#collapse-cfb5f1b5888a24efc43a5f3a4b37d137"
        aria-expanded="true"
      >
        SpringCloud
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-cfb5f1b5888a24efc43a5f3a4b37d137"
           role="tabpanel" aria-labelledby="heading-cfb5f1b5888a24efc43a5f3a4b37d137">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/memory_blog/2023/08/22/%E4%BB%8E%E9%9B%B6%E5%BC%80%E5%A7%8B%E6%9E%84%E5%BB%BA%E5%88%86%E5%B8%83%E5%BC%8F%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84%EF%BC%9A%E7%94%A8Dubbo%E5%92%8C%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83%E5%AE%9E%E7%8E%B0%E8%BF%9C%E7%A8%8B%E8%B0%83%E7%94%A8%E3%80%81%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0%E3%80%81%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86/" title="从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：24 天前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>欢迎阅读本篇博客！在当前大规模分布式系统的开发中，构建可靠的服务架构是至关重要的一环。为了实现远程方法调用、服务注册与发现以及配置管理等功能，使用 <code> </code>Dubbo<code> </code> 和注册中心（<code>ZooKeeper</code>、<code>Nacos</code>）成为了主流选择</p>
<p>本文将带领您一步步搭建一个强大的分布式服务架构，通过深入探索 <code>Dubbo</code> 和注册中心的使用方式，帮助您轻松实现高效的远程调用和服务管理。我们将详尽介绍如何安装、配置和集成<code>Nacos</code>和<code>ZooKeeper</code>作为注册中心，并结合<code> </code>Dubbo<code> </code>框架搭建完整的微服务架构</p>
<p>无论您是刚开始接触分布式架构，还是已经有一定经验，本文都将为您提供实用的技巧和最佳实践，以确保您的服务架构在性能、可靠性和扩展性方面都达到最佳状态</p>
<p>一起来构建强大而灵活的分布式服务架构吧！让我们从安装配置开始，逐步探索<code> </code>Dubbo<code> </code>与注册中心的集成，实现高效远程调用和服务管理的愉悦体验</p>
<h5 id="Dubbo-架构实现了什么？"><a href="#Dubbo-架构实现了什么？" class="headerlink" title="Dubbo 架构实现了什么？"></a><code>Dubbo</code> 架构实现了什么？</h5><p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230824134934927.png" alt="image-20230824134934927"></p>
<ul>
<li><h5 id="像调用本地方法一样，调用远程方法（2023-08-24午）"><a href="#像调用本地方法一样，调用远程方法（2023-08-24午）" class="headerlink" title="像调用本地方法一样，调用远程方法（2023/08/24午）"></a>像调用本地方法一样，调用远程方法（2023/08/24午）</h5></li>
<li><h5 id="以下是本文的行文思路："><a href="#以下是本文的行文思路：" class="headerlink" title="以下是本文的行文思路："></a>以下是本文的行文思路：</h5><ul>
<li>详细指南：使用ZooKeeper和Nacos搭建注册中心</li>
<li>架构实践：结合 <code>Dubbo</code> 实现灵活的远程方法调用</li>
<li>分布式协作：探索服务注册与发现的最佳实践</li>
<li>高效管理：利用注册中心进行配置管理的技巧与策略</li>
</ul>
</li>
</ul>
<h1 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h1><h2 id="搭建注册中心"><a href="#搭建注册中心" class="headerlink" title="搭建注册中心"></a>搭建注册中心</h2><ul>
<li><h5 id="我们接下来谈论的下载安装以及配置管理，都是在windows系统下进行的（2023-08-22晚）"><a href="#我们接下来谈论的下载安装以及配置管理，都是在windows系统下进行的（2023-08-22晚）" class="headerlink" title="我们接下来谈论的下载安装以及配置管理，都是在windows系统下进行的（2023/08/22晚）"></a>我们接下来谈论的下载安装以及配置管理，都是在windows系统下进行的（2023/08/22晚）</h5></li>
</ul>
<h4 id="下载安装"><a href="#下载安装" class="headerlink" title="下载安装"></a>下载安装</h4><ul>
<li><h5 id="ZooKeeper：Apache-ZooKeeper"><a href="#ZooKeeper：Apache-ZooKeeper" class="headerlink" title="ZooKeeper：Apache ZooKeeper"></a>ZooKeeper：<a target="_blank" rel="noopener" href="https://zookeeper.apache.org/releases.html">Apache ZooKeeper</a></h5></li>
<li><h5 id="Nacos：github-com"><a href="#Nacos：github-com" class="headerlink" title="Nacos：github.com"></a>Nacos：<a target="_blank" rel="noopener" href="https://github.com/alibaba/nacos/tags">github.com</a></h5></li>
<li><p>这里我们提供了ZeeKeeper和Nacos的下载方式，还有其他的下载方式，这里就不展示了</p>
</li>
<li><h5 id="ZooKeeper的安压缩包下载后，直接解压就行，详细过程可以参考这篇博客👇："><a href="#ZooKeeper的安压缩包下载后，直接解压就行，详细过程可以参考这篇博客👇：" class="headerlink" title="ZooKeeper的安压缩包下载后，直接解压就行，详细过程可以参考这篇博客👇："></a>ZooKeeper的安压缩包下载后，直接解压就行，详细过程可以参考这篇博客👇：</h5></li>
<li><p><a target="_blank" rel="noopener" href="https://dgrt.cn/a/1604886.html?action=onClick">Windows 安装 Zookeeper 详细步骤 (dgrt.cn)</a></p>
</li>
<li><h5 id="Nacos的下载则更加简单，直接拉取GitHub源代码就可以，参考官方文档👇："><a href="#Nacos的下载则更加简单，直接拉取GitHub源代码就可以，参考官方文档👇：" class="headerlink" title="Nacos的下载则更加简单，直接拉取GitHub源代码就可以，参考官方文档👇："></a>Nacos的下载则更加简单，直接拉取GitHub源代码就可以，参考官方文档👇：</h5></li>
<li><p><a target="_blank" rel="noopener" href="https://nacos.io/zh-cn/docs/quick-start.html">Nacos 快速开始</a></p>
</li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230823205911004.png" alt="image-20230823205911004"></p>
<h4 id="启动服务"><a href="#启动服务" class="headerlink" title="启动服务"></a>启动服务</h4><ul>
<li><h5 id="在ZooKeeper的bin目录下，双击zkServer-cmd即可快速启动注册中心："><a href="#在ZooKeeper的bin目录下，双击zkServer-cmd即可快速启动注册中心：" class="headerlink" title="在ZooKeeper的bin目录下，双击zkServer.cmd即可快速启动注册中心："></a>在ZooKeeper的bin目录下，双击zkServer.cmd即可快速启动注册中心：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230822121439364.png" alt="image-20230822121439364"></p>
<ul>
<li><h5 id="同理，在Nacos的bin目录下，双击startup-cmd即可快速启动注册中心："><a href="#同理，在Nacos的bin目录下，双击startup-cmd即可快速启动注册中心：" class="headerlink" title="同理，在Nacos的bin目录下，双击startup.cmd即可快速启动注册中心："></a>同理，在Nacos的bin目录下，双击startup.cmd即可快速启动注册中心：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230822121744746.png" alt="image-20230822121744746"></p>
<ul>
<li><h5 id="或者，在bin目录下，执行以下命令（单机运行）："><a href="#或者，在bin目录下，执行以下命令（单机运行）：" class="headerlink" title="或者，在bin目录下，执行以下命令（单机运行）："></a>或者，在bin目录下，执行以下命令（单机运行）：</h5></li>
</ul>
<figure class="highlight dos"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dos">startup.<span class="hljs-built_in">cmd</span> -m standalone<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230823210003483.png" alt="image-20230823210003483"></p>
<h2 id="远程方法调用"><a href="#远程方法调用" class="headerlink" title="远程方法调用"></a>远程方法调用</h2><ul>
<li><h5 id="Dubbo-官网：-3-基于-Spring-Boot-Starter-开发微服务应用-Apache-Dubbo-https-cn-Dubbo-apache-org-zh-cn-overview-mannual-java-sdk-quick-start-spring-boot"><a href="#Dubbo-官网：-3-基于-Spring-Boot-Starter-开发微服务应用-Apache-Dubbo-https-cn-Dubbo-apache-org-zh-cn-overview-mannual-java-sdk-quick-start-spring-boot" class="headerlink" title="Dubbo 官网：[3 - 基于 Spring Boot Starter 开发微服务应用 | Apache  Dubbo ](https://cn. Dubbo .apache.org/zh-cn/overview/mannual/java-sdk/quick-start/spring-boot/)"></a><code>Dubbo</code> 官网：[3 - 基于 Spring Boot Starter 开发微服务应用 | Apache  <code>Dubbo</code> ](<a target="_blank" rel="noopener" href="https://cn/">https://cn</a>. <code>Dubbo</code> .apache.org/zh-cn/overview/mannual/java-sdk/quick-start/spring-boot/)</h5></li>
<li><p>我们要基于 <code>Dubbo</code> 实现远程调用服务，实现很简单，参考官网文档就可以，这里简单说一下调用流程：</p>
<ul>
<li>启动注册中心</li>
<li>服务提供者 -&gt; 服务注册</li>
<li>消费者调用服务 -&gt; 服务发现</li>
<li>服务调用成功</li>
</ul>
</li>
<li><h5 id="这里，我们使用官网文档给出的示例代码，简单梳理下-Dubbo-实现服务远程调用的流程：（2023-08-22晚）"><a href="#这里，我们使用官网文档给出的示例代码，简单梳理下-Dubbo-实现服务远程调用的流程：（2023-08-22晚）" class="headerlink" title="这里，我们使用官网文档给出的示例代码，简单梳理下 Dubbo 实现服务远程调用的流程：（2023/08/22晚）"></a>这里，我们使用官网文档给出的示例代码，简单梳理下 <code>Dubbo</code> 实现服务远程调用的流程：（2023/08/22晚）</h5></li>
<li><h5 id="如上，ZooKeeper注册中心已经启动成功了"><a href="#如上，ZooKeeper注册中心已经启动成功了" class="headerlink" title="如上，ZooKeeper注册中心已经启动成功了"></a>如上，ZooKeeper注册中心已经启动成功了</h5></li>
<li><h5 id="服务提供者-gt-服务注册："><a href="#服务提供者-gt-服务注册：" class="headerlink" title="服务提供者 -&gt; 服务注册："></a>服务提供者 -&gt; 服务注册：</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@DubboService</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">DemoServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">DemoService</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">sayHello</span><span class="hljs-params">(String name)</span> &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Hello &quot;</span> + name;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230822131312100.png" alt="image-20230822131312100"></p>
<ul>
<li><h5 id="消费者调用服务-gt-服务发现："><a href="#消费者调用服务-gt-服务发现：" class="headerlink" title="消费者调用服务 -&gt; 服务发现："></a>消费者调用服务 -&gt; 服务发现：</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Component</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Task</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">CommandLineRunner</span> &#123;<br>    <span class="hljs-meta">@DubboReference</span><br>    <span class="hljs-keyword">private</span> DemoService demoService;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">run</span><span class="hljs-params">(String... args)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> demoService.sayHello(<span class="hljs-string">&quot;world&quot;</span>);<br>        System.out.println(<span class="hljs-string">&quot;Receive result ======&gt; &quot;</span> + result);<br><br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Thread</span>(()-&gt; &#123;<br>            <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    Thread.sleep(<span class="hljs-number">1000</span>);<br>                    System.out.println(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>() + <span class="hljs-string">&quot; Receive result ======&gt; &quot;</span> + demoService.sayHello(<span class="hljs-string">&quot;world&quot;</span>));<br>                &#125; <span class="hljs-keyword">catch</span> (InterruptedException e) &#123;<br>                    e.printStackTrace();<br>                    Thread.currentThread().interrupt();<br>                &#125;<br>            &#125;<br>        &#125;).start();<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230822131141978.png" alt="image-20230822131141978"></p>
<ul>
<li><h5 id="服务调用成功："><a href="#服务调用成功：" class="headerlink" title="服务调用成功："></a>服务调用成功：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230822130943864.png" alt="image-20230822130943864"></p>
<h2 id="服务注册与发现"><a href="#服务注册与发现" class="headerlink" title="服务注册与发现"></a>服务注册与发现</h2><ul>
<li><p>在拉取到官方文档中的示例代码并成功运行之后，我们需要在自己的项目中使用 ** <code>Dubbo</code> +Nacos 实现远程服务调用**</p>
</li>
<li><h5 id="成功下载安装Nacos注册中心，启动运行：（2023-08-24午）"><a href="#成功下载安装Nacos注册中心，启动运行：（2023-08-24午）" class="headerlink" title="成功下载安装Nacos注册中心，启动运行：（2023/08/24午）"></a>成功下载安装Nacos注册中心，启动运行：（2023/08/24午）</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230824133939409.png" alt="image-20230824133939409"></p>
<ul>
<li><h5 id="如下，在项目中引入相关依赖包："><a href="#如下，在项目中引入相关依赖包：" class="headerlink" title="如下，在项目中引入相关依赖包："></a>如下，在项目中引入相关依赖包：</h5></li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.Dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>Dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.1.8<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba.nacos<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>nacos-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.2.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li>在服务提供者和消费者中，分别添加如下配置：</li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">Dubbo:</span><br><span class="hljs-attr">application:</span><br>  <span class="hljs-attr">name:</span>  <span class="hljs-string">Dubbo-springboot-demo-provider</span><br><span class="hljs-attr">protocol:</span><br>  <span class="hljs-attr">name:</span>  <span class="hljs-string">Dubbo</span> <br>  <span class="hljs-attr">port:</span> <span class="hljs-number">-1</span><br><span class="hljs-attr">registry:</span><br>  <span class="hljs-attr">id:</span> <span class="hljs-string">nacos-registry</span><br>  <span class="hljs-attr">address:</span> <span class="hljs-string">nacos://localhost:8848</span><br></code></pre></td></tr></table></figure>

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">Dubbo:</span><br><span class="hljs-attr">application:</span><br>  <span class="hljs-attr">name:</span>  <span class="hljs-string">Dubbo-springboot-demo-client</span><br><span class="hljs-attr">protocol:</span><br>  <span class="hljs-attr">name:</span>  <span class="hljs-string">Dubbo</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">-1</span><br><span class="hljs-attr">registry:</span><br>  <span class="hljs-attr">id:</span> <span class="hljs-string">nacos-registry</span><br>  <span class="hljs-attr">address:</span> <span class="hljs-string">nacos://localhost:8848</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="添加-DubboService注解，作为服务提供者，将该service方法注册到注册中心："><a href="#添加-DubboService注解，作为服务提供者，将该service方法注册到注册中心：" class="headerlink" title="添加@DubboService注解，作为服务提供者，将该service方法注册到注册中心："></a>添加@DubboService注解，作为服务提供者，将该service方法注册到注册中心：</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 内部接口服务实现类</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@author</span> memory</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@DubboService</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">InnerInterfaceInfoServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">InnerInterfaceInfoService</span> &#123;<br>	........................<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="添加-DubboReference注解，作为消费者，从注册中心拉取对应服务，并成功调用："><a href="#添加-DubboReference注解，作为消费者，从注册中心拉取对应服务，并成功调用：" class="headerlink" title="添加@DubboReference注解，作为消费者，从注册中心拉取对应服务，并成功调用："></a>添加@DubboReference注解，作为消费者，从注册中心拉取对应服务，并成功调用：</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@DubboReference</span><br><span class="hljs-keyword">private</span> InnerUserService innerUserService;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 4.1.校验accessKey</span><br>  <span class="hljs-comment">// todo 从数据库中查询, accessKey是否分配给该用户</span><br>  <span class="hljs-keyword">if</span> (accessKey == <span class="hljs-literal">null</span> || !accessKey.equals(<span class="hljs-string">&quot;memory&quot;</span>)) &#123;<br>      <span class="hljs-keyword">return</span> handleNoAuth(response);<br>  &#125;<br>  <span class="hljs-comment">// accessKey是否分配给该用户</span><br>  <span class="hljs-type">User</span> <span class="hljs-variable">invokeUser</span> <span class="hljs-operator">=</span> innerUserService.getInvokeUser(accessKey);<br>  <span class="hljs-keyword">if</span> (invokeUser == <span class="hljs-literal">null</span>) &#123;<br>      <span class="hljs-keyword">return</span> handleNoAuth(response);<br>  &#125;<br></code></pre></td></tr></table></figure>

<h2 id="配置管理"><a href="#配置管理" class="headerlink" title="配置管理"></a>配置管理</h2><ul>
<li><h5 id="在服务提供者和消费者中，分别添加如下配置：（2023-08-24午）"><a href="#在服务提供者和消费者中，分别添加如下配置：（2023-08-24午）" class="headerlink" title="在服务提供者和消费者中，分别添加如下配置：（2023/08/24午）"></a>在服务提供者和消费者中，分别添加如下配置：（2023/08/24午）</h5></li>
</ul>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">Dubbo:</span><br><span class="hljs-attr">application:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">Dubbo-springboot-demo-provider</span><br><span class="hljs-attr">protocol:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">Dubbo</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">-1</span><br><span class="hljs-attr">registry:</span><br>  <span class="hljs-attr">id:</span> <span class="hljs-string">nacos-registry</span><br>  <span class="hljs-attr">address:</span> <span class="hljs-string">nacos://localhost:8848</span><br></code></pre></td></tr></table></figure>

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">Dubbo:</span><br><span class="hljs-attr">application:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">Dubbo-springboot-demo-client</span><br><span class="hljs-attr">protocol:</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">Dubbo</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">-1</span><br><span class="hljs-attr">registry:</span><br>  <span class="hljs-attr">id:</span> <span class="hljs-string">nacos-registry</span><br>  <span class="hljs-attr">address:</span> <span class="hljs-string">nacos://localhost:8848</span><br></code></pre></td></tr></table></figure>

<h2 id="Nacos"><a href="#Nacos" class="headerlink" title="Nacos"></a>Nacos</h2><blockquote>
<p>2024年4月26日</p>
</blockquote>
<p>🍖 推荐阅读：</p>
<ul>
<li><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/zouhong/p/16639508.html">NACOS动态配置 - 小破孩楼主 - 博客园 (cnblogs.com)</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_20957669/article/details/128939241">Nacos简介（一）-CSDN博客</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_20957669/article/details/132068216">Nacos:服务注册与发现(四）-CSDN博客</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/add3456b2ba8">Nacos命名空间、分组、DataID三者关系 - 简书 (jianshu.com)</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_39209927/article/details/136498614">一文看懂Nacos如何实现高效、动态的配置中心管理_nacos 动态配置-CSDN博客</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_54187478/article/details/134792493">Nacos：现代微服务架构中的动态服务发现和配置管理_服务的动态管理和配置-CSDN博客</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_55733979/article/details/131067474">Nacos最为配置中心，实现动态配置_nacos动态配置-CSDN博客</a></p>
</li>
</ul>
<blockquote>
<p>2024年6月7日</p>
</blockquote>
<p>很久没有真正实战过微服务了，基本上都是学了些理论基础，最近一次都是去年学习黑马教程微服务时写了 Demo练习。</p>
<p>今天正式实战微服务，以 API 接口开放平台为例。</p>
<p>子服务中导入依赖：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-config<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-discovery<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>一定要注意版本兼容问题啊，这点就不细说了，直接去官网查就行：</p>
<p>🍖 推荐阅读：<a target="_blank" rel="noopener" href="https://sca.aliyun.com/docs/2021/overview/version-explain/?spm=5176.29160081.0.0.74801a157QLVDg">版本发布说明 | https://sca.aliyun.com</a></p>
<p>我还是建议自己总结出一套最正确常用的依赖集合，这样自己做项目就会方便很多。</p>
<p>Nacos 作为 注册中心和配置中心，来看下配置文件：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">cloud:</span><br>  <span class="hljs-attr">nacos:</span><br>    <span class="hljs-attr">discovery:</span><br>      <span class="hljs-attr">server-addr:</span> <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span><span class="hljs-string">:8848</span><br>    <span class="hljs-attr">config:</span><br>      <span class="hljs-attr">import-check:</span><br>        <span class="hljs-attr">enabled:</span> <span class="hljs-literal">false</span><br></code></pre></td></tr></table></figure>

<p>很清晰，以 本地启动的 nacos 为注册中心，服务名称为 memory-client。</p>
<p>启动项目后，看到这样的提示，那就说明已经该服务注册成功了：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240607102508186.png" alt="image-20240607102508186"></p>
<p>查看 Nacos ：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240607104006059.png" alt="image-20240607104006059"></p>
<p>将 memory-core，memory-gateway，memory-client三个服务启动</p>
<p>其中，memory-core 作为 bubbo 服务提供者，其下三个 dubbo 服务也成功注册到 Nacos 注册中心：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># Dubbo</span><br><span class="hljs-attr">dubbo:</span><br>  <span class="hljs-attr">application:</span><br>    <span class="hljs-attr">name:</span> <span class="hljs-string">api-invoke-server</span><br>  <span class="hljs-attr">protocol:</span><br>    <span class="hljs-attr">name:</span> <span class="hljs-string">dubbo</span><br>    <span class="hljs-attr">port:</span> <span class="hljs-number">-1</span><br>  <span class="hljs-attr">registry:</span><br>    <span class="hljs-attr">id:</span> <span class="hljs-string">api-invoke</span><br>    <span class="hljs-attr">address:</span> <span class="hljs-string">nacos://localhost:8848</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240610203202683.png" alt="image-20240610203202683"></p>
<h2 id="OpenFeign"><a href="#OpenFeign" class="headerlink" title="OpenFeign"></a>OpenFeign</h2><blockquote>
<p>2024年6月12日</p>
</blockquote>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- 添加 openfeign 框架依赖 --&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/he__xu/article/details/120892236">nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0-CSDN博客</a></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 内部用户服务</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/user&quot; )</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserFeignClient</span> &#123;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 数据库中查是否已分配给用户秘钥（accessKey）</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> accessKey</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke&quot;)</span><br>    User <span class="hljs-title function_">getInvokeUser</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;accessKey&quot;)</span> String accessKey)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240612232052768.png" alt="image-20240612232052768"></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/u012161251/article/details/132706311">启动服务报错 For ‘xxx’ URL not provided. Will try picking an instance via load-balancing-CSDN博客</a></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.memory.gateway;<br><br><span class="hljs-keyword">import</span> org.junit.jupiter.api.Test;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;  <br><span class="hljs-keyword">import</span> org.springframework.boot.test.context.SpringBootTest;  <br><span class="hljs-keyword">import</span> org.springframework.cloud.client.ServiceInstance;  <br><span class="hljs-keyword">import</span> org.springframework.cloud.client.discovery.DiscoveryClient;  <br><span class="hljs-keyword">import</span> org.springframework.test.context.ActiveProfiles;  <br>  <br><span class="hljs-keyword">import</span> java.util.List;<br><br><span class="hljs-keyword">import</span> <span class="hljs-keyword">static</span> org.junit.jupiter.api.Assertions.*;<br><br><span class="hljs-meta">@SpringBootTest</span>  <br><span class="hljs-meta">@ActiveProfiles(&quot;dev&quot;)</span> <span class="hljs-comment">// 根据你的配置，可能需要指定活动配置文件  </span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">NacosDiscoveryTest</span> &#123;  <br>  <br>    <span class="hljs-meta">@Autowired</span>  <br>    <span class="hljs-keyword">private</span> DiscoveryClient discoveryClient;  <br>  <br>    <span class="hljs-meta">@Test</span>  <br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">testServiceDiscovery</span><span class="hljs-params">()</span> &#123;  <br>        <span class="hljs-comment">// 获取所有服务名称  </span><br>        List&lt;String&gt; services = discoveryClient.getServices();  <br>        assertNotNull(services, <span class="hljs-string">&quot;Services list should not be null&quot;</span>);  <br>        assertFalse(services.isEmpty(), <span class="hljs-string">&quot;Services list should not be empty&quot;</span>);  <br>  <br>        <span class="hljs-comment">// 检查 &#x27;memory-core&#x27; 服务是否存在  </span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">containsMemoryCore</span> <span class="hljs-operator">=</span> services.contains(<span class="hljs-string">&quot;memory-core&quot;</span>);  <br>        assertTrue(containsMemoryCore, <span class="hljs-string">&quot;&#x27;memory-core&#x27; should be in the services list&quot;</span>);  <br>  <br>        <span class="hljs-comment">// 获取 &#x27;memory-core&#x27; 的服务实例列表  </span><br>        List&lt;ServiceInstance&gt; instances = discoveryClient.getInstances(<span class="hljs-string">&quot;memory-core&quot;</span>);  <br>        assertNotNull(instances, <span class="hljs-string">&quot;Instances list for &#x27;memory-core&#x27; should not be null&quot;</span>);  <br>        assertFalse(instances.isEmpty(), <span class="hljs-string">&quot;Instances list for &#x27;memory-core&#x27; should not be empty&quot;</span>);  <br>  <br>        <span class="hljs-comment">// 验证服务实例信息（例如，打印 IP 地址和端口）  </span><br>        <span class="hljs-keyword">for</span> (ServiceInstance instance : instances) &#123;  <br>            System.out.println(<span class="hljs-string">&quot;Service ID: &quot;</span> + instance.getServiceId());  <br>            System.out.println(<span class="hljs-string">&quot;Host: &quot;</span> + instance.getHost());  <br>            System.out.println(<span class="hljs-string">&quot;Port: &quot;</span> + instance.getPort());  <br>            <span class="hljs-comment">// ... 其他验证  </span><br>        &#125;  <br>    &#125;  <br>  <br>    <span class="hljs-comment">// 注意：这里假设了有一个名为 &#x27;assertTrue&#x27; 的断言方法，但 Java 的 JUnit 5 并没有这个方法。  </span><br>    <span class="hljs-comment">// 你应该使用 assertTrue(boolean condition) 或其他相应的断言方法。  </span><br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240612230445281.png" alt="image-20240612230445281"></p>
<blockquote>
<p>2024年6月14日</p>
</blockquote>
<p>特么踩了六天的坑，总算搞定了：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 内部用户服务</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/user/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserFeignClient</span> &#123;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 数据库中查是否已分配给用户秘钥（accessKey）</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> accessKey</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke&quot;)</span><br>    User <span class="hljs-title function_">getInvokeUser</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;accessKey&quot;)</span> String accessKey)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>就这么简单的几行客户端代码，折腾了我好几天，总是报错还找不到解决方法。</p>
<p>首先，@RequestParam(value = “accessKey”)，这行代码必须加上。原因：</p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/he__xu/article/details/120892236">nested exception is java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0-CSDN博客</a></p>
<figure class="highlight aspectj"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs aspectj">在 SpringMVC 和 Springboot 中都可以使用 <span class="hljs-meta">@RequestParam</span> 注解，不指定 value 的用法，为什么到了 Spring cloud 中的 Feign 这里就不行了呢？<br><br>这是因为和 Feign 的实现有关。Feign 的底层使用的是 httpclient，在低版本中会产生这个问题，高版本中已经对这个问题修复了。<br></code></pre></td></tr></table></figure>

<p>接下来就是 path = “/api/user/inner” 的配置了，这行代码要是不配置，直接找不到对应服务，报这个错：</p>
<p>feign.RetryableException: Connection refused: connect executing GET <a target="_blank" rel="noopener" href="http://memory-core/api/user/get/invoke?accessKey=memory">http://memory-core/api/user/get/invoke?accessKey=memory</a></p>
<p>看到这个恶心的错误没，没能在注册中心里找到对应服务。</p>
<p>为了解决这个问题，我还编写了 demo 测试代码，查看了下注册中心里到底有没有注册成功这个服务，都在上面👆</p>
<p>最后是这个：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240614223433246.png" alt="image-20240614223433246"></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_39740187/article/details/122907272">No qualifying bean of type ‘org.springframework.boot.autoconfigure.http.HttpMessageConverters‘_no qualifying bean of type ‘org.springframework.bo-CSDN博客</a></p>
<p>解决方案就在上面，我在 memory-backend-gateway 模块下面写了一个配置类：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.memory.gateway.config;<br><br><span class="hljs-keyword">import</span> org.springframework.beans.factory.ObjectProvider;<br><span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;<br><span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.http.HttpMessageConverters;<br><span class="hljs-keyword">import</span> org.springframework.context.annotation.Bean;<br><span class="hljs-keyword">import</span> org.springframework.context.annotation.Configuration;<br><span class="hljs-keyword">import</span> org.springframework.http.converter.HttpMessageConverter;<br><br><span class="hljs-keyword">import</span> java.util.stream.Collectors;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * ClassName: HttpMesConConfiguration</span><br><span class="hljs-comment"> * Package: com.memory.gateway.config</span><br><span class="hljs-comment"> * Description:</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@Author</span> Memory</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@Create</span> 2024/6/14 22:35</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@Version</span> 1.0</span><br><span class="hljs-comment"> */</span><br><br><span class="hljs-meta">@Configuration</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HttpMesConConfiguration</span> &#123;<br>    <span class="hljs-meta">@Bean</span><br>    <span class="hljs-meta">@ConditionalOnMissingBean</span><br>    <span class="hljs-keyword">public</span> HttpMessageConverters <span class="hljs-title function_">messageConverters</span><span class="hljs-params">(ObjectProvider&lt;HttpMessageConverter&lt;?&gt;&gt; converters)</span> &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">HttpMessageConverters</span>(converters.orderedStream().collect(Collectors.toList()));<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>这个问题就完美解决了。</p>
<p>搞定了。</p>
<h3 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h3><p>memory-backend-gateway 和 memory-backend-core-service 模块引入依赖：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br> <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>编写客户端，这边我新增了一个公共模块：memory-backend-server-client，客户端代码写这里了：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 内部用户服务</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/user/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserFeignClient</span> &#123;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 数据库中查是否已分配给用户秘钥（accessKey）</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> accessKey</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke&quot;)</span><br>    User <span class="hljs-title function_">getInvokeUser</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;accessKey&quot;)</span> String accessKey)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>memory-backend-gateway 启动类：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@EnableFeignClients(basePackages = &quot;com.memory.client.feignClient&quot;)</span><br></code></pre></td></tr></table></figure>

<p>接下来还有什么好说的，直接调用就行了：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Resource</span><br> <span class="hljs-comment">// private UserDubboService userDubboService;</span><br> <span class="hljs-keyword">private</span> UserFeignClient userFeignClient;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 3.2.校验accessKey</span><br>      <span class="hljs-comment">// todo 从数据库中查询, accessKey是否分配给该用户</span><br>      <span class="hljs-keyword">if</span> (accessKey == <span class="hljs-literal">null</span> || !accessKey.equals(<span class="hljs-string">&quot;memory&quot;</span>)) &#123;<br>          <span class="hljs-keyword">return</span> handleNoAuth(response);<br>      &#125;<br>      <span class="hljs-comment">// accessKey 是否分配给该用户</span><br>      <span class="hljs-comment">// User invokeUser = userDubboService.getInvokeUser(accessKey);</span><br>      <span class="hljs-type">User</span> <span class="hljs-variable">invokeUser</span> <span class="hljs-operator">=</span> userFeignClient.getInvokeUser(accessKey);<br>      <span class="hljs-keyword">if</span> (invokeUser == <span class="hljs-literal">null</span>) &#123;<br>          <span class="hljs-keyword">return</span> handleNoAuth(response);<br>      &#125;<br></code></pre></td></tr></table></figure>

<p>真正调用到的是这个接口：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 该服务仅内部调用，不是给前端的</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/user/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserInnerController</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">UserFeignClient</span> &#123;<br><br>    <span class="hljs-meta">@Resource</span><br>    <span class="hljs-keyword">private</span> UserService userService;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 数据库中查是否已分配给用户秘钥（accessKey）</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> accessKey</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke&quot;)</span><br>    <span class="hljs-keyword">public</span> User <span class="hljs-title function_">getInvokeUser</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;accessKey&quot;)</span> String accessKey)</span> &#123;<br>        <span class="hljs-keyword">return</span> userService.getInvokeUser(accessKey);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<blockquote>
<p>2024年6月16日</p>
</blockquote>
<p>特么真服了，还有这样的问题：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240616104828701.png" alt="image-20240616104828701"></p>
<p>加这行注解吧：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">main:</span><br>  <span class="hljs-attr">web-application-type:</span> <span class="hljs-string">reactive</span><br>  <span class="hljs-attr">allow-bean-definition-overriding:</span> <span class="hljs-literal">true</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240616105548316.png" alt="image-20240616105548316"></p>
<p>好，所有 Feign 客户端下的抽象方法中参数都必须这么写：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/interface/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">InterfaceInfoFeignClient</span> &#123;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 从数据库中查询模拟接口是否存在（请求路径、请求方法、请求参数）</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> path</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> method</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/interfaceInfo&quot;)</span><br>    InterfaceInfo <span class="hljs-title function_">getInterfaceInfo</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;path&quot;)</span> String path, <span class="hljs-meta">@RequestParam(value = &quot;method&quot;)</span> String method)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/user/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserFeignClient</span> &#123;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 数据库中查是否已分配给用户秘钥（accessKey）</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> accessKey</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke&quot;)</span><br>    User <span class="hljs-title function_">getInvokeUser</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;accessKey&quot;)</span> String accessKey)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@FeignClient(name = &quot;memory-core&quot;, path = &quot;/api/user/interface/inner&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">UserInterfaceInfoFeignClient</span> &#123;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 调用接口统计</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> interfaceInfoId</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userId</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/get/invoke/count&quot;)</span><br>    <span class="hljs-type">boolean</span> <span class="hljs-title function_">invokeCount</span><span class="hljs-params">(<span class="hljs-meta">@RequestParam(value = &quot;interfaceInfoId&quot;)</span> <span class="hljs-type">long</span> interfaceInfoId, <span class="hljs-meta">@RequestParam(value = &quot;userId&quot;)</span> <span class="hljs-type">long</span> userId)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="Gateway"><a href="#Gateway" class="headerlink" title="Gateway"></a>Gateway</h2><h3 id="接口路由"><a href="#接口路由" class="headerlink" title="接口路由"></a>接口路由</h3><h3 id="权限校验"><a href="#权限校验" class="headerlink" title="权限校验"></a>权限校验</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 2. 访问来源校验</span><br>      <span class="hljs-comment">// 2.1. 黑白名单</span><br>      <span class="hljs-keyword">if</span> (!IP_WHITE_HOSTS.contains(sourceAddress)) &#123;<br>          <span class="hljs-comment">// 设置错误状态码并返回</span><br>          response.setStatusCode(HttpStatus.FORBIDDEN);<br>          <span class="hljs-keyword">return</span> response.setComplete();<br>      &#125;<br>      <span class="hljs-comment">// 2.2.内部调用</span><br>      <span class="hljs-keyword">if</span> (antPathMatcher.match(<span class="hljs-string">&quot;/ **inner** /&quot;</span>, path)) &#123;<br>          response.setStatusCode(HttpStatus.FORBIDDEN);<br>          <span class="hljs-keyword">return</span> response.setComplete();<br>      &#125;<br>      <span class="hljs-comment">// 2.3.聚合文档</span><br>      <span class="hljs-keyword">if</span> (SWAGGER_API_DOC_HOST.contains(sourceAddress)) &#123;<br>          log.info(<span class="hljs-string">&quot;聚合 API 文档访问，不需要校验&quot;</span>);<br>          <span class="hljs-keyword">return</span> chain.filter(exchange);<br>      &#125;<br></code></pre></td></tr></table></figure>

<h3 id="聚合文档"><a href="#聚合文档" class="headerlink" title="聚合文档"></a>聚合文档</h3><p><a target="_blank" rel="noopener" href="https://doc.xiaominfo.com/docs/middleware-sources/spring-cloud-gateway/spring-gateway-introduction">Spring Cloud Gateway网关聚合 | Knife4j (xiaominfo.com)</a></p>
<p>分别在 memory-backend-core-service 模块和 memory-backend-application 模块中，导入以下坐标：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- https://doc.xiaominfo.com/knife4j/documentation/get_start.html--&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.xiaoymin<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>knife4j-openapi2-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.3.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>配置文件：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">knife4j:</span><br>  <span class="hljs-attr">enable:</span> <span class="hljs-literal">true</span><br></code></pre></td></tr></table></figure>

<p>在网关模块 memory-backend-gateway 中，导入以下坐标：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.xiaoymin<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>knife4j-gateway-spring-boot-starter<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>           <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.3.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>配置文件：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">knife4j:</span><br>  <span class="hljs-attr">gateway:</span><br>    <span class="hljs-attr">enabled:</span> <span class="hljs-literal">true</span><br>    <span class="hljs-comment"># 指定服务发现的模式聚合微服务文档</span><br>    <span class="hljs-attr">strategy:</span> <span class="hljs-string">discover</span><br>    <span class="hljs-attr">discover:</span><br>      <span class="hljs-attr">enabled:</span> <span class="hljs-literal">true</span><br>      <span class="hljs-comment"># 指定版本号(Swagger2|OpenAPI3)</span><br>      <span class="hljs-attr">version :</span> <span class="hljs-string">swagger2</span><br>      <span class="hljs-comment"># 需要排除的微服务(eg:网关服务)</span><br>      <span class="hljs-attr">excluded-services:</span><br>        <span class="hljs-bullet">-</span> <span class="hljs-string">memory-gateway</span><br></code></pre></td></tr></table></figure>

<p>到这里，使用 Gateway 实现聚合文档就很轻松的完成了，可以根据需要按需配置，推荐在这里研究学习：</p>
<p>🥣 <a target="_blank" rel="noopener" href="https://doc.xiaominfo.com/docs/middleware-sources/spring-cloud-gateway/spring-gateway-introduction">Spring Cloud Gateway网关聚合 | Knife4j (xiaominfo.com)</a></p>
<p>访问：<a target="_blank" rel="noopener" href="http://localhost:8090/api/doc.html#/home">localhost</a>，即可查看到聚合 API 文档，十分方便。</p>
<p>如果这里引用了 Gateway 请求过滤器，可能会有无权限访问的情况发生：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240616111252073.png" alt="image-20240616111252073"></p>
<p>在权限校验中，选择直接放行聚合 API 文档访问：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 2. 访问来源校验</span><br>      <span class="hljs-comment">// 2.1. 黑白名单</span><br>      <span class="hljs-keyword">if</span> (!IP_WHITE_HOSTS.contains(sourceAddress)) &#123;<br>          <span class="hljs-comment">// 设置错误状态码并返回</span><br>          response.setStatusCode(HttpStatus.FORBIDDEN);<br>          <span class="hljs-keyword">return</span> response.setComplete();<br>      &#125;<br>      <span class="hljs-comment">// 2.2.内部调用</span><br>      <span class="hljs-keyword">if</span> (antPathMatcher.match(<span class="hljs-string">&quot;/ **inner** /&quot;</span>, path)) &#123;<br>          response.setStatusCode(HttpStatus.FORBIDDEN);<br>          <span class="hljs-keyword">return</span> response.setComplete();<br>      &#125;<br>      <span class="hljs-comment">// 2.3.聚合文档</span><br>      <span class="hljs-keyword">if</span> (SWAGGER_API_DOC_HOST.contains(sourceAddress)) &#123;<br>          log.info(<span class="hljs-string">&quot;聚合 API 文档访问，不需要校验&quot;</span>);<br>          <span class="hljs-keyword">return</span> chain.filter(exchange);<br>      &#125;<br></code></pre></td></tr></table></figure>

<h3 id="分布式-session-登录"><a href="#分布式-session-登录" class="headerlink" title="分布式 session 登录"></a>分布式 session 登录</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- redis --&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.session<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-session-data-redis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-comment"># server</span><br><span class="hljs-attr">server:</span><br>  <span class="hljs-attr">address:</span> <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span><br>  <span class="hljs-attr">port:</span> <span class="hljs-number">8101</span><br>  <span class="hljs-attr">servlet:</span><br>    <span class="hljs-attr">context-path:</span> <span class="hljs-string">/api</span><br>    <span class="hljs-comment"># cookie</span><br>    <span class="hljs-attr">session:</span><br>      <span class="hljs-attr">cookie:</span><br>        <span class="hljs-attr">max-age:</span> <span class="hljs-number">2592000</span><br>        <span class="hljs-attr">path:</span> <span class="hljs-string">/api</span><br></code></pre></td></tr></table></figure>

<h3 id="跨域解决"><a href="#跨域解决" class="headerlink" title="跨域解决"></a>跨域解决</h3><figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs reasonml"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * ClassName: CorsConfig</span><br><span class="hljs-comment"> * Package: com.memory.gateway.config</span><br><span class="hljs-comment"> * Description: 处理跨域</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * @Author Memory</span><br><span class="hljs-comment"> * @Create 2024/6/16 12:32</span><br><span class="hljs-comment"> * @Version 1.0</span><br><span class="hljs-comment"> */</span><br><br>@Configuration<br>public <span class="hljs-keyword">class</span> CorsConfig &#123;<br>    @Bean<br>    public CorsWebFilter cors<span class="hljs-constructor">WebFilter()</span> &#123;<br>        CorsConfiguration config = <span class="hljs-keyword">new</span> <span class="hljs-constructor">CorsConfiguration()</span>;<br>        config.add<span class="hljs-constructor">AllowedMethod(<span class="hljs-string">&quot;*&quot;</span>)</span>;<br>        config.set<span class="hljs-constructor">AllowCredentials(<span class="hljs-params">true</span>)</span>;<br>        config.set<span class="hljs-constructor">AllowedOriginPatterns(Collections.<span class="hljs-params">singletonList</span>(<span class="hljs-string">&quot;*&quot;</span>)</span>);<br>        config.add<span class="hljs-constructor">ExposedHeader(<span class="hljs-string">&quot;*&quot;</span>)</span>;<br>        UrlBasedCorsConfigurationSource source = <span class="hljs-keyword">new</span> <span class="hljs-constructor">UrlBasedCorsConfigurationSource(<span class="hljs-params">new</span> PathPatternParser()</span>);<br>        source.register<span class="hljs-constructor">CorsConfiguration(<span class="hljs-string">&quot;/**&quot;</span>, <span class="hljs-params">config</span>)</span>;<br>        return <span class="hljs-keyword">new</span> <span class="hljs-constructor">CorsWebFilter(<span class="hljs-params">source</span>)</span>;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="请求限流"><a href="#请求限流" class="headerlink" title="请求限流"></a>请求限流</h3><h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/memory_blog/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1/" class="category-chain-item">微服务</a>
  
  
    <span>></span>
    
  <a href="/memory_blog/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringCloud/" class="category-chain-item">SpringCloud</a>
  
  
    <span>></span>
    
  <a href="/memory_blog/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringCloud/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/memory_blog/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/memory_blog/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">#微服务</a>
      
        <a href="/memory_blog/tags/SpringCloud/">#SpringCloud</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>从零开始构建分布式服务架构：用 `Dubbo` 和注册中心实现远程调用、服务注册与发现、配置管理</div>
      <div>https://test.atomgit.net/memory_blog/2023/08/22/从零开始构建分布式服务架构：用Dubbo和注册中心实现远程调用、服务注册与发现、配置管理/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年8月22日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年6月14日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/memory_blog/2023/08/23/SpringBoot%E7%AC%AC%E4%B8%89%E6%96%B9%E6%9C%8D%E5%8A%A1%E5%BC%80%E5%8F%91%E5%AE%9E%E8%B7%B5%EF%BC%9A%E7%89%88%E6%9C%AC%E5%85%BC%E5%AE%B9%E6%80%A7%E5%92%8C%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86/" title="SpringBoot第三方服务开发实践：版本兼容性和依赖管理">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">SpringBoot第三方服务开发实践：版本兼容性和依赖管理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/memory_blog/2023/08/17/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%20API%20%E7%BD%91%E5%85%B3%EF%BC%9A%E5%8E%9F%E7%90%86%E3%80%81%E5%8A%9F%E8%83%BD%E5%92%8C%E7%94%A8%E9%80%94/" title="深入理解 API 网关：原理、功能和用途">
                        <span class="hidden-mobile">深入理解 API 网关：原理、功能和用途</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/memory_blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/memory_blog/js/events.js" ></script>
<script  src="/memory_blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/memory_blog/js/local-search.js" ></script>

  <script defer src="/memory_blog/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/memory_blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
